@echo off
echo ========================================
echo LimeReader Quick Check
echo ========================================
echo.

set "ERROR_COUNT=0"

:: Check if installer exists
echo [1/5] Checking installer file...
if exist "installer\LimeReader_Setup_v2.7.2.exe" (
    for %%F in ("installer\LimeReader_Setup_v2.7.2.exe") do (
        set "SIZE=%%~zF"
        if %%~zF GTR 10000000 (
            echo [OK] Installer found (%%~zF bytes)
        ) else (
            echo [WARN] Installer too small (%%~zF bytes)
            set /a ERROR_COUNT+=1
        )
    )
) else (
    echo [ERROR] Installer not found!
    set /a ERROR_COUNT+=1
)
echo.

:: Check if build output exists
echo [2/5] Checking build output...
if exist "build\bin\Release\LimeReader.exe" (
    echo [OK] Executable found
) else (
    echo [ERROR] Executable not found at build\bin\Release\LimeReader.exe
    set /a ERROR_COUNT+=1
)
echo.

:: Check essential DLLs in build directory
echo [3/5] Checking essential DLLs...
set "ESSENTIAL_DLLS=0"
for %%D in (Qt6Core.dll Qt6Gui.dll Qt6Widgets.dll libgcc_s_seh-1.dll libstdc++-6.dll libwinpthread-1.dll) do (
    if exist "build\bin\Release\%%D" (
        set /a ESSENTIAL_DLLS+=1
    ) else (
        echo [WARN] Missing: %%D
    )
)
echo [OK] Found %ESSENTIAL_DLLS%/6 essential DLLs
if %ESSENTIAL_DLLS% LSS 6 (
    echo [WARN] Some DLLs are missing, run create_installer_simple.bat
    set /a ERROR_COUNT+=1
)
echo.

:: Check Qt plugins
echo [4/5] Checking Qt plugins...
if exist "build\bin\Release\platforms\qwindows.dll" (
    echo [OK] Qt platforms plugin found
) else (
    echo [ERROR] Missing platforms\qwindows.dll (CRITICAL!)
    set /a ERROR_COUNT+=1
)
echo.

:: Check Poppler
echo [5/5] Checking Poppler libraries...
set "POPPLER_COUNT=0"
for %%D in (libpoppler-153.dll libpoppler-cpp-2.dll) do (
    if exist "build\bin\Release\%%D" (
        set /a POPPLER_COUNT+=1
    ) else if exist "mingw64-poppler\bin\%%D" (
        echo [INFO] %%D found in source, will be packed
        set /a POPPLER_COUNT+=1
    )
)
if %POPPLER_COUNT% GEQ 2 (
    echo [OK] Poppler libraries available
) else (
    echo [WARN] Poppler libraries not found, PDF support may not work
)
echo.

:: Summary
echo ========================================
if %ERROR_COUNT% EQU 0 (
    echo [SUCCESS] All checks passed!
    echo Ready for testing.
) else (
    echo [WARNING] Found %ERROR_COUNT% issue(s)
    echo Please review the warnings above.
)
echo ========================================
echo.

:: Suggest next steps
echo Next Steps:
echo.
if %ERROR_COUNT% GTR 0 (
    echo 1. Run: build.bat
    echo 2. Run: create_installer_simple.bat
    echo 3. Run this check again
) else (
    echo Ready to test! Choose a method:
    echo.
    echo Method 1: Windows Sandbox (Recommended)
    echo   - Double-click: test_in_sandbox.wsb
    echo.
    echo Method 2: VirtualBox
    echo   - See: TESTING_GUIDE.md
    echo.
    echo Method 3: Manual test
    echo   - Copy installer to another PC
    echo   - Or create new Windows user account
)
echo.
pause

